//   -------------------- iSharePoint -------------------- //
//  
//   Company:	IT Complex, LLC
//   Project:	Smart.Common
//   File name:	SqlSettings.cs
//   Developer:	Igor Solomatov
//   Created:	28.08.2012
//  
//   -------------------- iSharePoint -------------------- //

using System;
using System.ComponentModel;

namespace Smart.SQL
{
	/// <summary>
	/// Sql Settings values
	/// </summary>
	[Localizable(false)]
	public class SqlSettings
	{
		public SqlSettings()
		{
		}

		public SqlSettings(string src)
			: this()
		{
			var fields = src.Split('#');

			SqlServerMain = fields[0];
			SqlServerFailover = fields[1];
			DatabaseName = fields[2];
		}

		private int? _key = null;

		public int GetKey()
		{
			return
				_key ??
				((int)(_key =
						DatabaseName.GetHashCodeIgnoreCase() ^
						SqlServerMain.GetHashCodeIgnoreCase() ^
						SqlServerFailover.GetHashCodeIgnoreCase()));
		}

		/// <summary>
		/// Main SQL Server
		/// </summary>
		public string SqlServerMain { get; set; }

		/// <summary>
		/// Failover SQL Server
		/// </summary>
		public string SqlServerFailover { get; set; }

		/// <summary>
		/// Database name
		/// </summary>
		public string DatabaseName { get; set; }

		/// <summary>
		/// Checks whether settings is initialized
		/// </summary>
		public bool IsInitialized { get { return !H.IsAnyNullOrEmpty(SqlServerMain, DatabaseName); } }

		protected virtual string Save()
		{
			return
				String.Concat(SqlServerMain, "#", SqlServerFailover, "#", DatabaseName);
		}
	}
}